import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path';  
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'

export default defineConfig({
  plugins: [vue(), cssInjectedByJsPlugin(),],
  resolve: {  
    alias: {  
      '@': resolve(__dirname, './src'), // 将 '@' 映射到 'src' 目录  
    },  
  },
  define: { 'process.env.NODE_ENV': '"production"' },
  build: {  
    // 设置输出目录  
    outDir: '../Build/vue3-components',  
    emptyOutDir: true,
    cssCodeSplit: false, // 将 CSS 打包到 JS 文件  
    lib: {  
      entry: 'src/index.js', // 入口文件  
      name: 'bariumComponents', // 库名  
      fileName: (format) => `components.${format}.js`, // 输出的文件名  
      formats: ['es', 'umd'], // 输出 ESM 和 UMD 格式  
    },  
    rollupOptions: {  
      external: ['vue'], // 外部依赖，不打包进库文件
      output: {
        globals: {
          vue: 'Vue' // 全局变量映射
        },
        exports: 'named'
      }
    } 
  },  
  server: {
    proxy: {
      "/api": {
        target: "http://192.168.2.231:8088",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api'),
      },
      "/tts_all": {
        target: "http://192.168.2.231:9898",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/tts_all/, '/tts_all'),
      },
      "/test": {
        target: "http://192.168.2.231:7860/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/test/, '')
      }, 
      "/bim-rest": {
        target: "http://172.18.80.62",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/bim-rest/, '/bim-rest'),
      },
    }
  }
})
